package ${packageName}.dto;

import ${packageName}.domain.${classInfo.className};
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.time.Instant;
import java.math.BigDecimal;
import java.io.Serializable;
import java.util.Objects;
import java.util.Optional;
<#if useLombok>
import lombok.Data;
</#if>
/**
 * ${classInfo.classComment}
 *
 * @author ${authorName} ${.now?string('yyyy-MM-dd')}
 */
@ApiModel("${classInfo.className}DTO")
<#if useLombok>
@Data
</#if>
public class ${classInfo.className}DTO implements Serializable{
    private static final long serialVersionUID = 1L;
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
    <#list classInfo.fieldList as fieldItem >
    /**
     * ${fieldItem.fieldComment}
     */
    <#if fieldItem.required && fieldItem.fieldName != "id">
    @NotNull
    </#if>
    <#if fieldItem.size gt 0>
    @Size(max = ${fieldItem.size?c})
    </#if>
    @ApiModelProperty(value = "${fieldItem.fieldComment}"<#if fieldItem.exampleValue?exists>, example = "${fieldItem.exampleValue}"</#if> <#if fieldItem.required && fieldItem.fieldName != "id">, required = true</#if>)
    private ${fieldItem.fieldClass} ${fieldItem.fieldName};

    </#list>
    public ${classInfo.className}DTO() {
        // Empty constructor needed for Jackson.
    }
    public ${classInfo.className}DTO(${classInfo.className} ${classInfo.className?uncap_first}) {
    <#list classInfo.fieldList as fieldItem >
        this.${fieldItem.fieldName} = ${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}();
    </#list>
    }
    public static ${classInfo.className}DTO from(${classInfo.className} ${classInfo.className?uncap_first}) {
        return new ${classInfo.className}DTO(${classInfo.className?uncap_first});
    }
    public ${classInfo.className} to${classInfo.className}() {
        ${classInfo.className} ${classInfo.className?uncap_first} = new ${classInfo.className}();
    <#list classInfo.fieldList as fieldItem >
        ${classInfo.className?uncap_first}.set${fieldItem.fieldName?cap_first}(this.get${fieldItem.fieldName?cap_first}());
    </#list>

        return ${classInfo.className?uncap_first};
    }
    public ${classInfo.className} to${classInfo.className}(${classInfo.className} ${classInfo.className?uncap_first}) {
        Objects.requireNonNull(${classInfo.className?uncap_first}, "${classInfo.className?uncap_first} must not be null");

    <#list classInfo.fieldList as fieldItem >
        Optional.ofNullable(${fieldItem.fieldName}).ifPresent(${classInfo.className?uncap_first}::set${fieldItem.fieldName?cap_first});
    </#list>

        return ${classInfo.className?uncap_first};
    }

<#if !useLombok>
<#list classInfo.fieldList as fieldItem >
    public ${fieldItem.fieldClass} get${fieldItem.fieldName?cap_first}() {
        return ${fieldItem.fieldName};
    }
    public void set${fieldItem.fieldName?cap_first}(${fieldItem.fieldClass} ${fieldItem.fieldName}) {
        this.${fieldItem.fieldName} = ${fieldItem.fieldName};
    }

</#list>
</#if>

</#if>

}
